<template>
  <div>
    <!-- 最外层容器 -->
    <el-container>
      <!-- 上半部分：顶栏 -->
      <el-header class="layout-header" style="overflow: hidden">
        <h1 style="display: inline !important;">书笺小驿运营管理平台</h1>
        <el-button
            style="float: right;top: 100px !important;margin-top: 10px!important;"
        icon="el-icon-s-home"  @click="exit()"  type="primary" round>
          退出登录</el-button>
        <h2 style="display: inline !important;float: right;margin-top: 15px!important;">欢迎 "{{admin.username}}" 登录</h2>
      </el-header>
      <!-- 下半部分：容器 -->
      <el-container class="layout-body">
        <!-- 下半部分的左侧边栏 -->
        <el-aside class="layout-aside">
          <el-menu
              router
              :default-active="activeMenuItemPath"
              class="el-menu-vertical-demo"
              background-color="#222c32"
              text-color="#fff"
              active-text-color="#fff">
            <!-- 首页 -->
            <el-menu-item index="/sys-admin">
              <i class="el-icon-s-home"></i>
              <span>首页</span>
            </el-menu-item>
            <!-- 前台管理 -->
            <el-submenu index="7">
              <template slot="title">
                <i class="el-icon-monitor"></i>
                <span>前台管理</span>
              </template>
              <el-menu-item index="/hot">
                <i class="el-icon-search"></i>
                <span>热搜</span>
              </el-menu-item>
              <el-menu-item index="/activity">
                <i class="el-icon-s-flag"></i>
                <span>活动</span>
              </el-menu-item>
              <el-menu-item index="/sys-admin/product/banner">
                <i class="el-icon-picture"></i>
                <span>轮播图</span>
              </el-menu-item>
              <el-menu-item index="/comment">
                <i class="el-icon-s-comment"></i>
                <span>评论</span>
              </el-menu-item>
              <el-menu-item index="/notice">
                <i class="el-icon-date"></i>
                <span>公告</span>
              </el-menu-item>
            </el-submenu>
            <!-- 商品管理 -->
            <el-submenu index="3">
              <template slot="title">
                <i class="el-icon-s-goods"></i>
                <span>商品管理</span>
              </template>
              <el-menu-item index="/goodsAddNew">
                <i class="el-icon-circle-plus"></i>
                <span slot="title">添加商品</span>
              </el-menu-item>
              <el-menu-item index="goodslist">
                <i class="el-icon-s-goods"></i>
                <span slot="title">商品管理</span>
              </el-menu-item>
              <el-menu-item index="/pack">
                <i class="el-icon-takeaway-box"></i>
                <span slot="title">包装管理</span>
              </el-menu-item>
              <el-menu-item index="press">
                <i class="el-icon-office-building"></i>
                <span slot="title">出版社</span>
              </el-menu-item>
              <el-menu-item index="/categoryGoods">
                <i class="el-icon-s-unfold"></i>
                <span slot="title">商品类别</span>
              </el-menu-item>

            </el-submenu>
            <!-- 订单管理 -->
            <el-submenu index="4">
              <template slot="title">
                <i class="el-icon-s-order"></i>
                <span>订单管理</span>
              </template>
              <el-menu-item index="/orders1">
                <i class="el-icon-s-order"></i>
                <span slot="title">订单查询</span>
              </el-menu-item>
              <el-menu-item index="/orders2">
                <i class="el-icon-folder-delete"></i>
                <span slot="title">待支付订单</span>
              </el-menu-item>
              <el-menu-item index="/orders3">
                <i class="el-icon-folder-remove"></i>
                <span slot="title">待发货/已支付管理</span>
              </el-menu-item>
              <el-menu-item index="/orders4">
                <i class="el-icon-folder-checked"></i>
                <span slot="title">待收货/已发货订单</span>
              </el-menu-item>
              <el-menu-item index="/orders5">
                <i class="el-icon-edit-outline"></i>
                <span slot="title">已收货订单</span>
              </el-menu-item>
<!--              <el-menu-item index="/orders5">-->
<!--                <i class="el-icon-edit-outline"></i>-->
<!--                <span slot="title">用户未评论订单</span>-->
<!--              </el-menu-item>-->
            </el-submenu>
            <el-submenu index="5">
              <template slot="title">
                <i class="el-icon-user-solid"></i>
                <span>用户管理</span>
              </template>
              <el-menu-item index="/adminuser">
              <i class="el-icon-user-solid"></i>
              <span slot="title">用户管理</span>
            </el-menu-item>
              <el-menu-item index="/admin">
              <i class="el-icon-user"></i>
              <span slot="title">管理员管理</span>
            </el-menu-item>

            </el-submenu>


          </el-menu>
        </el-aside>
        <!-- 下半部分的右侧主体部分 -->
        <el-main class="layout-main">
          <router-view/>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  data() {
    return {
      activeMenuItemPath: '',
      admin:null
    }
  },
  methods: {
    exit() {
      this.$confirm("确定退出系统吗", '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        localStorage.removeItem('admin');
        this.admin=null;
       location.href="/"
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });

    }
  },
  mounted() {
    let path = this.$router.currentRoute.path;
    if (path.startsWith('/goodsAddNew')) {
      this.activeMenuItemPath = '/goodsAddNew';
    } else {
      this.activeMenuItemPath = path;
    }

    this.admin=localStorage.getItem('admin');
    if(this.admin==null){
      location.href='/';
    }
    console.log( "=======",localStorage.getItem('admin'))
    this.admin=JSON.parse(this.admin)
    console.log( "admin=======",this.admin.id)
  },


}
</script>

<style>
.layout-header {
  background: #1684b0;
}

.layout-header h1 {
  color: #fff;
  text-align: left;
  line-height: 60px;
}

.layout-body {
  position: absolute;
  top: 60px;
  bottom: 0;
  left: 0;
  right: 0;
}

.layout-aside {
  background: #222c32;
}

.layout-aside i {
  color: #fff !important;
}

.layout-main {
}

.el-menu-item.is-active {
  background: #2d3c4d !important;
}
</style>